#include "enemybullet.h"

EnemyBullet::EnemyBullet(QGraphicsScene *m_scene)
{
    scene = m_scene;
    root = QFileInfo(__FILE__).absolutePath();
    speed = 20;
    for(int i=0;i<3;i++){
        pix.append(QPixmap(root+"big_bad_bullet_0"+QString::number(i+1)+".png"));
    }
    state = 0;
}

QRectF EnemyBullet::boundingRect() const
{
    return QRectF(-pix[0].width()*0.5,-pix[0].height()*0.5,pix[0].width(),pix[0].height()-10);
}

void EnemyBullet::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->drawPixmap(-pix[state].width()*0.5,-pix[state].height(),pix[state]);
}

void EnemyBullet::advance(int phase)
{
    state = (state+1)%3;
    QGraphicsItem::setPos(mapToScene(speed,0));
}

bool EnemyBullet::isVisible() const
{
    return QGraphicsItem::isVisible();
}

void EnemyBullet::setVisible(bool visible)
{
    QGraphicsItem::setVisible(true);
}
